import Component from './index.vue';
import { dataTypeList, outputEventList } from './../constants'

const meta = {
  componentName: 'View1',
  title: '视图1',
  type: 'view',
  w: 4,
  h: 3,
  imgName:'view1',
  props: [
    {
      name: 'componentId',
      rules: {
        required: false,
      },
      desc: '组件编号',
      defaultValue: 'M-GJ1',
    },
    {
      name: 'viewType',
      desc: '组件类型',
      defaultValue: '告警类',
    },
    {
      name: 'size',
      propType: {
        required: false,
      },
      desc: '组件尺寸',
      defaultValue: '4*3',
    },
    {
      name: 'title',
      rules: {
        type: 'string',
        required: true
      },
      desc: '组件标题',
      defaultValue: ''
    },
    {
      name: 'desc',
      rules: {
        required: false,
      },
      desc: '组件描述',
      defaultValue: ''
    },
    {
      name: 'imageId',
      rules: {
        required: false,
      },
      desc: '组件缩略图',
      defaultValue: '1'
    },
    // 通用属性
    {
      name: 'dataType',
      rules: {
        required: false,
      },
      desc: '取数类型',
      defaultValue: '1'
    },
    {
      name: 'dataSet',
      rules: {
        required: false,
      },
      desc: '数据配置',
      defaultValue: '',
      visible: false
    },
    {
      name: 'isDrillingDown',
      rules: {
        required: false,
      },
      desc: '是否支持下钻',
      defaultValue: false
    },
    {
      name: 'refreshFrequency',
      rules: {
        required: false,
      },
      desc: '数据刷新频率',
      defaultValue: 3
    },
    {
      name: 'isDesensitization',
      rules: {
        required: false,
      },
      desc: '脱敏配置',
      defaultValue: false
    },
    {
      name: 'desensitizationFields',
      rules: {
        required: false,
      },
      desc: '脱敏字段',
      defaultValue:  []
    },
    {
      name: 'outputEvents',
      rules: {
        required: false,
      },
      desc: '可输出事件',
      defaultValue:  []
    },
    {
      name: 'inputEvents',
      rules: {
        required: false,
      },
      desc: '可输入事件',
      defaultValue:  []
    },
  ],
  configure: {
    basicProps: {
      title: '组件基本信息',
      override: [
        {
          name: 'componentId',
          setter: 'StringSetter',
        },
        {
          name: 'viewType',
          setter: 'StringSetter',
        },
        {
          name: 'size',
          setter: 'StringSetter',
        },
        {
          name: 'title',
          setter: 'InputSetter',
        },
        {
          name: 'desc',
          setter: {
            componentName:'InputSetter',
            props:{
              maxlength: 500,
              type:'textarea'
            }
          },
        },
       {
        name:'imageId',
        setter: {
          componentName: 'UploadSetter',
        }
       }
      ]
    },
    commonProps: {
      title: '组件通用属性',
      override: [
        {
          name: 'dataType',
          setter: {
            componentName: 'SelectSetter',
            props: {
              options: dataTypeList,
              onBeforeChange: (value: String, node: any) => {
                node.value.componentMeta.props.forEach((item:any) => {
                  if(item.name === 'dataSet') {
                    // 取数类型为静态数据时，则数据配置显示
                    item.visible = value === '2' ? true : false;
                  }
                });
                return value;
              }
            },
          },
        },
        {
          name: 'dataSet',
          setter: 'EditMockSetter',
        },
        {
          name: 'isDrillingDown',
          setter: 'BooleanSetter',
        },
        {
          name: 'refreshFrequency',
          setter: {
            componentName: 'NumberSetter',
            props: {
              text: '分钟刷新一次'
            },
          }
        },
        {
          name: 'isDesensitization',
          setter: 'BooleanSetter',
        },
        {
          name: 'desensitizationFields',
          setter: 'DesensitizationFieldSetter',
        },
        {
          name: 'outputEvents',
          setter: {
            componentName: 'ListSetter',
            props: {
              options:  ['资产类型', '告警类型', '单位'],
            },
          },
        },
        {
          name: 'inputEvents',
          setter: {
            componentName: 'CheckboxSetter',
            props: {
              options: outputEventList,
            },
          },
        },
      ]
    },
  },
}


export default {
  componentName: meta.componentName,
  componentMeta: meta,
  component: Component
}
